package com.lcn.netty.utils;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.time.Duration;

public class JedisPoolUtils {

    private static JedisPool jedisPool;

    static {
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        poolConfig.setMaxTotal(10); // 最大连接数
        poolConfig.setMaxIdle(10); // 最大空闲连接数
        poolConfig.setMinIdle(5); // 最小空闲连接数
        poolConfig.setMaxWait(Duration.ofMillis(1500)); // 最长等待时间 ms
        jedisPool = new JedisPool(poolConfig, "127.0.0.1", 5379, 1000);
    }

    public static Jedis getJedis() {
        return jedisPool.getResource();
    }

}
